{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv('./data/titanic.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "0    22.0\n1    38.0\n2    26.0\n3    35.0\n4    35.0\nName: Age, dtype: float64"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age = df['Age']\n",
    "age[:5]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "array([22., 38., 26., 35., 35.])"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age.values[:5]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "data": {
      "text/plain": "PassengerId                          1\nSurvived                             0\nPclass                               3\nName           Braund, Mr. Owen Harris\nSex                               male\nAge                               22.0\nSibSp                                1\nParch                                0\nTicket                       A/5 21171\nFare                              7.25\nCabin                              NaN\nEmbarked                             S\nName: 0, dtype: object"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 拿到第一个数据，索引依旧是从0开始\n",
    "df.iloc[0]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "data": {
      "text/plain": "   PassengerId  Survived  Pclass  \\\n0            1         0       3   \n1            2         1       1   \n2            3         1       3   \n3            4         1       1   \n4            5         0       3   \n\n                                                Name     Sex   Age  SibSp  \\\n0                            Braund, Mr. Owen Harris    male  22.0      1   \n1  Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0      1   \n2                             Heikkinen, Miss. Laina  female  26.0      0   \n3       Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1   \n4                           Allen, Mr. William Henry    male  35.0      0   \n\n   Parch            Ticket     Fare Cabin Embarked  \n0      0         A/5 21171   7.2500   NaN        S  \n1      0          PC 17599  71.2833   C85        C  \n2      0  STON/O2. 3101282   7.9250   NaN        S  \n3      0            113803  53.1000  C123        S  \n4      0            373450   8.0500   NaN        S  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>PassengerId</th>\n      <th>Survived</th>\n      <th>Pclass</th>\n      <th>Name</th>\n      <th>Sex</th>\n      <th>Age</th>\n      <th>SibSp</th>\n      <th>Parch</th>\n      <th>Ticket</th>\n      <th>Fare</th>\n      <th>Cabin</th>\n      <th>Embarked</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>0</td>\n      <td>3</td>\n      <td>Braund, Mr. Owen Harris</td>\n      <td>male</td>\n      <td>22.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>A/5 21171</td>\n      <td>7.2500</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>1</td>\n      <td>1</td>\n      <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n      <td>female</td>\n      <td>38.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>PC 17599</td>\n      <td>71.2833</td>\n      <td>C85</td>\n      <td>C</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>3</td>\n      <td>1</td>\n      <td>3</td>\n      <td>Heikkinen, Miss. Laina</td>\n      <td>female</td>\n      <td>26.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>STON/O2. 3101282</td>\n      <td>7.9250</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>4</td>\n      <td>1</td>\n      <td>1</td>\n      <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n      <td>female</td>\n      <td>35.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>113803</td>\n      <td>53.1000</td>\n      <td>C123</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>5</td>\n      <td>0</td>\n      <td>3</td>\n      <td>Allen, Mr. William Henry</td>\n      <td>male</td>\n      <td>35.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>373450</td>\n      <td>8.0500</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 也可以使用切片来拿到一部分数据\n",
    "df.iloc[0:5]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "   Survived  Pclass\n0         0       3\n1         1       1\n2         1       3\n3         1       1\n4         0       3",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Survived</th>\n      <th>Pclass</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0</td>\n      <td>3</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 不仅可以指定样本，也可以指定特征\n",
    "df.iloc[0:5, 1:3]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "\"None of ['Name'] are in the columns\"",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mKeyError\u001B[0m                                  Traceback (most recent call last)",
      "Cell \u001B[1;32mIn [15], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m df \u001B[38;5;241m=\u001B[39m \u001B[43mdf\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mset_index\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mName\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m      2\u001B[0m \u001B[38;5;66;03m# 直接通过名字标签来取数据\u001B[39;00m\n\u001B[0;32m      3\u001B[0m df\u001B[38;5;241m.\u001B[39mloc[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mHeikkinen, Miss. Laina\u001B[39m\u001B[38;5;124m'\u001B[39m]\n",
      "File \u001B[1;32m~\\PycharmProjects\\training\\venv\\Lib\\site-packages\\pandas\\util\\_decorators.py:331\u001B[0m, in \u001B[0;36mdeprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper\u001B[1;34m(*args, **kwargs)\u001B[0m\n\u001B[0;32m    325\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mlen\u001B[39m(args) \u001B[38;5;241m>\u001B[39m num_allow_args:\n\u001B[0;32m    326\u001B[0m     warnings\u001B[38;5;241m.\u001B[39mwarn(\n\u001B[0;32m    327\u001B[0m         msg\u001B[38;5;241m.\u001B[39mformat(arguments\u001B[38;5;241m=\u001B[39m_format_argument_list(allow_args)),\n\u001B[0;32m    328\u001B[0m         \u001B[38;5;167;01mFutureWarning\u001B[39;00m,\n\u001B[0;32m    329\u001B[0m         stacklevel\u001B[38;5;241m=\u001B[39mfind_stack_level(),\n\u001B[0;32m    330\u001B[0m     )\n\u001B[1;32m--> 331\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mfunc\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43margs\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43mkwargs\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32m~\\PycharmProjects\\training\\venv\\Lib\\site-packages\\pandas\\core\\frame.py:6001\u001B[0m, in \u001B[0;36mDataFrame.set_index\u001B[1;34m(self, keys, drop, append, inplace, verify_integrity)\u001B[0m\n\u001B[0;32m   5998\u001B[0m                 missing\u001B[38;5;241m.\u001B[39mappend(col)\n\u001B[0;32m   6000\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m missing:\n\u001B[1;32m-> 6001\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mNone of \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mmissing\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m are in the columns\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m   6003\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m inplace:\n\u001B[0;32m   6004\u001B[0m     frame \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\n",
      "\u001B[1;31mKeyError\u001B[0m: \"None of ['Name'] are in the columns\""
     ]
    }
   ],
   "source": [
    "df = df.set_index('Name')\n",
    "# 直接通过名字标签来取数据\n",
    "df.loc['Heikkinen, Miss. Laina']"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "data": {
      "text/plain": "7.925"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取当前数据的某一列信息\n",
    "df.loc['Heikkinen, Miss. Laina', 'Fare']"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "data": {
      "text/plain": "                                              PassengerId  Survived  Pclass  \\\nName                                                                          \nHeikkinen, Miss. Laina                                  3         1       3   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)            4         1       1   \nAllen, Mr. William Henry                                5         0       3   \n\n                                                 Sex   Age  SibSp  Parch  \\\nName                                                                       \nHeikkinen, Miss. Laina                        female  26.0      0      0   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1      0   \nAllen, Mr. William Henry                        male  35.0      0      0   \n\n                                                        Ticket    Fare Cabin  \\\nName                                                                           \nHeikkinen, Miss. Laina                        STON/O2. 3101282   7.925   NaN   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)            113803  53.100  C123   \nAllen, Mr. William Henry                                373450   8.050   NaN   \n\n                                             Embarked  \nName                                                   \nHeikkinen, Miss. Laina                              S  \nFutrelle, Mrs. Jacques Heath (Lily May Peel)        S  \nAllen, Mr. William Henry                            S  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>PassengerId</th>\n      <th>Survived</th>\n      <th>Pclass</th>\n      <th>Sex</th>\n      <th>Age</th>\n      <th>SibSp</th>\n      <th>Parch</th>\n      <th>Ticket</th>\n      <th>Fare</th>\n      <th>Cabin</th>\n      <th>Embarked</th>\n    </tr>\n    <tr>\n      <th>Name</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>Heikkinen, Miss. Laina</th>\n      <td>3</td>\n      <td>1</td>\n      <td>3</td>\n      <td>female</td>\n      <td>26.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>STON/O2. 3101282</td>\n      <td>7.925</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Futrelle, Mrs. Jacques Heath (Lily May Peel)</th>\n      <td>4</td>\n      <td>1</td>\n      <td>1</td>\n      <td>female</td>\n      <td>35.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>113803</td>\n      <td>53.100</td>\n      <td>C123</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Allen, Mr. William Henry</th>\n      <td>5</td>\n      <td>0</td>\n      <td>3</td>\n      <td>male</td>\n      <td>35.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>373450</td>\n      <td>8.050</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['Heikkinen, Miss. Laina':'Allen, Mr. William Henry', :]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "data": {
      "text/plain": "                                                    PassengerId  Survived  \\\nName                                                                        \nBraund, Mr. Owen Harris                                       1         0   \nCumings, Mrs. John Bradley (Florence Briggs Tha...            2         1   \nHeikkinen, Miss. Laina                                        3         1   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)                  4         1   \nAllen, Mr. William Henry                                      5         0   \n...                                                         ...       ...   \nMontvila, Rev. Juozas                                       887         0   \nGraham, Miss. Margaret Edith                                888         1   \nJohnston, Miss. Catherine Helen \"Carrie\"                    889         0   \nBehr, Mr. Karl Howell                                       890         1   \nDooley, Mr. Patrick                                         891         0   \n\n                                                    Pclass     Sex   Age  \\\nName                                                                       \nBraund, Mr. Owen Harris                                  3    male  22.0   \nCumings, Mrs. John Bradley (Florence Briggs Tha...       1  female  38.0   \nHeikkinen, Miss. Laina                                   3  female  26.0   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)             1  female  35.0   \nAllen, Mr. William Henry                                 3    male  35.0   \n...                                                    ...     ...   ...   \nMontvila, Rev. Juozas                                    2    male  27.0   \nGraham, Miss. Margaret Edith                             1  female  19.0   \nJohnston, Miss. Catherine Helen \"Carrie\"                 3  female   NaN   \nBehr, Mr. Karl Howell                                    1    male  26.0   \nDooley, Mr. Patrick                                      3    male  32.0   \n\n                                                    SibSp  Parch  \\\nName                                                               \nBraund, Mr. Owen Harris                                 1      0   \nCumings, Mrs. John Bradley (Florence Briggs Tha...      1      0   \nHeikkinen, Miss. Laina                                  0      0   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)            1      0   \nAllen, Mr. William Henry                                0      0   \n...                                                   ...    ...   \nMontvila, Rev. Juozas                                   0      0   \nGraham, Miss. Margaret Edith                            0      0   \nJohnston, Miss. Catherine Helen \"Carrie\"                1      2   \nBehr, Mr. Karl Howell                                   0      0   \nDooley, Mr. Patrick                                     0      0   \n\n                                                              Ticket  \\\nName                                                                   \nBraund, Mr. Owen Harris                                    A/5 21171   \nCumings, Mrs. John Bradley (Florence Briggs Tha...          PC 17599   \nHeikkinen, Miss. Laina                              STON/O2. 3101282   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)                  113803   \nAllen, Mr. William Henry                                      373450   \n...                                                              ...   \nMontvila, Rev. Juozas                                         211536   \nGraham, Miss. Margaret Edith                                  112053   \nJohnston, Miss. Catherine Helen \"Carrie\"                  W./C. 6607   \nBehr, Mr. Karl Howell                                         111369   \nDooley, Mr. Patrick                                           370376   \n\n                                                         Fare Cabin Embarked  \nName                                                                          \nBraund, Mr. Owen Harris                                7.2500   NaN        S  \nCumings, Mrs. John Bradley (Florence Briggs Tha...    71.2833   C85        C  \nHeikkinen, Miss. Laina                              1000.0000   NaN        S  \nFutrelle, Mrs. Jacques Heath (Lily May Peel)          53.1000  C123        S  \nAllen, Mr. William Henry                               8.0500   NaN        S  \n...                                                       ...   ...      ...  \nMontvila, Rev. Juozas                                 13.0000   NaN        S  \nGraham, Miss. Margaret Edith                          30.0000   B42        S  \nJohnston, Miss. Catherine Helen \"Carrie\"              23.4500   NaN        S  \nBehr, Mr. Karl Howell                                 30.0000  C148        C  \nDooley, Mr. Patrick                                    7.7500   NaN        Q  \n\n[891 rows x 11 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>PassengerId</th>\n      <th>Survived</th>\n      <th>Pclass</th>\n      <th>Sex</th>\n      <th>Age</th>\n      <th>SibSp</th>\n      <th>Parch</th>\n      <th>Ticket</th>\n      <th>Fare</th>\n      <th>Cabin</th>\n      <th>Embarked</th>\n    </tr>\n    <tr>\n      <th>Name</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>Braund, Mr. Owen Harris</th>\n      <td>1</td>\n      <td>0</td>\n      <td>3</td>\n      <td>male</td>\n      <td>22.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>A/5 21171</td>\n      <td>7.2500</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Cumings, Mrs. John Bradley (Florence Briggs Thayer)</th>\n      <td>2</td>\n      <td>1</td>\n      <td>1</td>\n      <td>female</td>\n      <td>38.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>PC 17599</td>\n      <td>71.2833</td>\n      <td>C85</td>\n      <td>C</td>\n    </tr>\n    <tr>\n      <th>Heikkinen, Miss. Laina</th>\n      <td>3</td>\n      <td>1</td>\n      <td>3</td>\n      <td>female</td>\n      <td>26.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>STON/O2. 3101282</td>\n      <td>1000.0000</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Futrelle, Mrs. Jacques Heath (Lily May Peel)</th>\n      <td>4</td>\n      <td>1</td>\n      <td>1</td>\n      <td>female</td>\n      <td>35.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>113803</td>\n      <td>53.1000</td>\n      <td>C123</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Allen, Mr. William Henry</th>\n      <td>5</td>\n      <td>0</td>\n      <td>3</td>\n      <td>male</td>\n      <td>35.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>373450</td>\n      <td>8.0500</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>Montvila, Rev. Juozas</th>\n      <td>887</td>\n      <td>0</td>\n      <td>2</td>\n      <td>male</td>\n      <td>27.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>211536</td>\n      <td>13.0000</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Graham, Miss. Margaret Edith</th>\n      <td>888</td>\n      <td>1</td>\n      <td>1</td>\n      <td>female</td>\n      <td>19.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>112053</td>\n      <td>30.0000</td>\n      <td>B42</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Johnston, Miss. Catherine Helen \"Carrie\"</th>\n      <td>889</td>\n      <td>0</td>\n      <td>3</td>\n      <td>female</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>2</td>\n      <td>W./C. 6607</td>\n      <td>23.4500</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Behr, Mr. Karl Howell</th>\n      <td>890</td>\n      <td>1</td>\n      <td>1</td>\n      <td>male</td>\n      <td>26.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>111369</td>\n      <td>30.0000</td>\n      <td>C148</td>\n      <td>C</td>\n    </tr>\n    <tr>\n      <th>Dooley, Mr. Patrick</th>\n      <td>891</td>\n      <td>0</td>\n      <td>3</td>\n      <td>male</td>\n      <td>32.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>370376</td>\n      <td>7.7500</td>\n      <td>NaN</td>\n      <td>Q</td>\n    </tr>\n  </tbody>\n</table>\n<p>891 rows × 11 columns</p>\n</div>"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['Heikkinen, Miss. Laina', 'Fare'] = 1000\n",
    "df"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "data": {
      "text/plain": "Name\nBraund, Mr. Owen Harris                                False\nCumings, Mrs. John Bradley (Florence Briggs Thayer)     True\nHeikkinen, Miss. Laina                                  True\nFutrelle, Mrs. Jacques Heath (Lily May Peel)            True\nAllen, Mr. William Henry                               False\n                                                       ...  \nMontvila, Rev. Juozas                                  False\nGraham, Miss. Margaret Edith                           False\nJohnston, Miss. Catherine Helen \"Carrie\"               False\nBehr, Mr. Karl Howell                                  False\nDooley, Mr. Patrick                                    False\nName: Fare, Length: 891, dtype: bool"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Fare'] > 40"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "data": {
      "text/plain": "                                                    PassengerId  Survived  \\\nName                                                                        \nCumings, Mrs. John Bradley (Florence Briggs Tha...            2         1   \nHeikkinen, Miss. Laina                                        3         1   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)                  4         1   \nMcCarthy, Mr. Timothy J                                       7         0   \nFortune, Mr. Charles Alexander                               28         0   \n\n                                                    Pclass     Sex   Age  \\\nName                                                                       \nCumings, Mrs. John Bradley (Florence Briggs Tha...       1  female  38.0   \nHeikkinen, Miss. Laina                                   3  female  26.0   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)             1  female  35.0   \nMcCarthy, Mr. Timothy J                                  1    male  54.0   \nFortune, Mr. Charles Alexander                           1    male  19.0   \n\n                                                    SibSp  Parch  \\\nName                                                               \nCumings, Mrs. John Bradley (Florence Briggs Tha...      1      0   \nHeikkinen, Miss. Laina                                  0      0   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)            1      0   \nMcCarthy, Mr. Timothy J                                 0      0   \nFortune, Mr. Charles Alexander                          3      2   \n\n                                                              Ticket  \\\nName                                                                   \nCumings, Mrs. John Bradley (Florence Briggs Tha...          PC 17599   \nHeikkinen, Miss. Laina                              STON/O2. 3101282   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)                  113803   \nMcCarthy, Mr. Timothy J                                        17463   \nFortune, Mr. Charles Alexander                                 19950   \n\n                                                         Fare        Cabin  \\\nName                                                                         \nCumings, Mrs. John Bradley (Florence Briggs Tha...    71.2833          C85   \nHeikkinen, Miss. Laina                              1000.0000          NaN   \nFutrelle, Mrs. Jacques Heath (Lily May Peel)          53.1000         C123   \nMcCarthy, Mr. Timothy J                               51.8625          E46   \nFortune, Mr. Charles Alexander                       263.0000  C23 C25 C27   \n\n                                                   Embarked  \nName                                                         \nCumings, Mrs. John Bradley (Florence Briggs Tha...        C  \nHeikkinen, Miss. Laina                                    S  \nFutrelle, Mrs. Jacques Heath (Lily May Peel)              S  \nMcCarthy, Mr. Timothy J                                   S  \nFortune, Mr. Charles Alexander                            S  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>PassengerId</th>\n      <th>Survived</th>\n      <th>Pclass</th>\n      <th>Sex</th>\n      <th>Age</th>\n      <th>SibSp</th>\n      <th>Parch</th>\n      <th>Ticket</th>\n      <th>Fare</th>\n      <th>Cabin</th>\n      <th>Embarked</th>\n    </tr>\n    <tr>\n      <th>Name</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>Cumings, Mrs. John Bradley (Florence Briggs Thayer)</th>\n      <td>2</td>\n      <td>1</td>\n      <td>1</td>\n      <td>female</td>\n      <td>38.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>PC 17599</td>\n      <td>71.2833</td>\n      <td>C85</td>\n      <td>C</td>\n    </tr>\n    <tr>\n      <th>Heikkinen, Miss. Laina</th>\n      <td>3</td>\n      <td>1</td>\n      <td>3</td>\n      <td>female</td>\n      <td>26.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>STON/O2. 3101282</td>\n      <td>1000.0000</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Futrelle, Mrs. Jacques Heath (Lily May Peel)</th>\n      <td>4</td>\n      <td>1</td>\n      <td>1</td>\n      <td>female</td>\n      <td>35.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>113803</td>\n      <td>53.1000</td>\n      <td>C123</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>McCarthy, Mr. Timothy J</th>\n      <td>7</td>\n      <td>0</td>\n      <td>1</td>\n      <td>male</td>\n      <td>54.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>17463</td>\n      <td>51.8625</td>\n      <td>E46</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Fortune, Mr. Charles Alexander</th>\n      <td>28</td>\n      <td>0</td>\n      <td>1</td>\n      <td>male</td>\n      <td>19.0</td>\n      <td>3</td>\n      <td>2</td>\n      <td>19950</td>\n      <td>263.0000</td>\n      <td>C23 C25 C27</td>\n      <td>S</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df['Fare'] > 40][:5]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%d\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "data": {
      "text/plain": "                                PassengerId  Survived  Pclass   Sex   Age  \\\nName                                                                        \nBraund, Mr. Owen Harris                   1         0       3  male  22.0   \nAllen, Mr. William Henry                  5         0       3  male  35.0   \nMoran, Mr. James                          6         0       3  male   NaN   \nMcCarthy, Mr. Timothy J                   7         0       1  male  54.0   \nPalsson, Master. Gosta Leonard            8         0       3  male   2.0   \n\n                                SibSp  Parch     Ticket     Fare Cabin  \\\nName                                                                     \nBraund, Mr. Owen Harris             1      0  A/5 21171   7.2500   NaN   \nAllen, Mr. William Henry            0      0     373450   8.0500   NaN   \nMoran, Mr. James                    0      0     330877   8.4583   NaN   \nMcCarthy, Mr. Timothy J             0      0      17463  51.8625   E46   \nPalsson, Master. Gosta Leonard      3      1     349909  21.0750   NaN   \n\n                               Embarked  \nName                                     \nBraund, Mr. Owen Harris               S  \nAllen, Mr. William Henry              S  \nMoran, Mr. James                      Q  \nMcCarthy, Mr. Timothy J               S  \nPalsson, Master. Gosta Leonard        S  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>PassengerId</th>\n      <th>Survived</th>\n      <th>Pclass</th>\n      <th>Sex</th>\n      <th>Age</th>\n      <th>SibSp</th>\n      <th>Parch</th>\n      <th>Ticket</th>\n      <th>Fare</th>\n      <th>Cabin</th>\n      <th>Embarked</th>\n    </tr>\n    <tr>\n      <th>Name</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>Braund, Mr. Owen Harris</th>\n      <td>1</td>\n      <td>0</td>\n      <td>3</td>\n      <td>male</td>\n      <td>22.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>A/5 21171</td>\n      <td>7.2500</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Allen, Mr. William Henry</th>\n      <td>5</td>\n      <td>0</td>\n      <td>3</td>\n      <td>male</td>\n      <td>35.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>373450</td>\n      <td>8.0500</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Moran, Mr. James</th>\n      <td>6</td>\n      <td>0</td>\n      <td>3</td>\n      <td>male</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>0</td>\n      <td>330877</td>\n      <td>8.4583</td>\n      <td>NaN</td>\n      <td>Q</td>\n    </tr>\n    <tr>\n      <th>McCarthy, Mr. Timothy J</th>\n      <td>7</td>\n      <td>0</td>\n      <td>1</td>\n      <td>male</td>\n      <td>54.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>17463</td>\n      <td>51.8625</td>\n      <td>E46</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>Palsson, Master. Gosta Leonard</th>\n      <td>8</td>\n      <td>0</td>\n      <td>3</td>\n      <td>male</td>\n      <td>2.0</td>\n      <td>3</td>\n      <td>1</td>\n      <td>349909</td>\n      <td>21.0750</td>\n      <td>NaN</td>\n      <td>S</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df['Sex'] == 'male'][:5]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "data": {
      "text/plain": "30.72664459161148"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df['Sex'] == 'male', 'Age'].mean()"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "outputs": [
    {
     "data": {
      "text/plain": "5"
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(df['Age'] > 70).sum()"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
